﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Xml;
using FirstFloor.ModernUI.Windows.Controls;
using FirstFloor.ModernUI.Presentation;

namespace ModernWSPView.Classes.Converters
{
    public class XmlEltToMuiLink : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Link result = null;

            if (value is XmlElement)
            {
                XmlElement xe = value as XmlElement;

                //===============================================================
                if (xe.Name == "ContentType")
                {
                    string url = string.Format(
                        "Pages/PageListFieldsOfContentType.xaml#{0}",
                        ((XmlElement)value).Attributes["ID"].Value);
                    result = new Link()
                    {
                        DisplayName = ((XmlElement)value).Attributes["Name"].Value,
                        Source = new Uri(url, UriKind.RelativeOrAbsolute)
                    };
                }
                //===============================================================
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //throw new NotImplementedException();
            return null;
        }
    }
}
